<template>
  <div class="conten">
    <el-form ref="form" :rules="rules" :model="formData" label-width="80px" class="form">
      <el-form-item label="短剧名称" prop="playlet_id">
        <el-select v-model="formData.playlet_id" remote filterable clearable placeholder="请选择" style="width: 250px">
          <el-option v-for="item in optionsList.playletList" :key="item.value" :disabled="item.is_exist && item.is_exist === 1 ? true : false" :label="item.label" :value="item.value"> </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div class="dialog-footer rowFlex">
      <div class="btns">
        <el-button class="btn" @click="close">取 消</el-button>
        <el-button class="btn" type="primary" :loading="loading" @click="onSubmit">确 定</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { POST_mini_app_playlet_popularSave } from '@/api/appContent/theater'
import { commonData } from '@/api/common'
export default {
  components: {
  },
  props: {
    data: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      loading: false,
      formData: {
        mini_app_id: window.localStorage.getItem('mini_app_id'),
        playlet_id: '',
        id: ''
      },
      optionsList: {
        playletList: []
      },
      rules: {
        playlet_id: [{ required: true, message: '请选择短剧', trigger: 'blur' }]
      }
    }
  },
  mounted() {
    this.onGetPlayletList()
    this.formData.playlet_id = this.data.playlet_id * 1 || ''
    this.formData.id = this.data.id || ''
    console.log(this.formData)
  },
  methods: {
    playletSelect(value) {
      this.formData.playlet_id = value
    },
    close() {
      this.$emit('cancel')
    },
    async onSubmit() {
      this.loading = true
      const params = this.formData
      this.$refs.form.validate((valid) => {
        if (valid) {
          POST_mini_app_playlet_popularSave(params).then((res) => {
            if (res.status_code == 1) {
              this.$message.success(res.msg)
              this.$emit('ok')
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
      this.loading = false
    },
    async onGetPlayletList() {
      const res = await commonData({
        type: 'miniAppPlaylet',
        column_type: '1',
        mini_app_id: this.formData.mini_app_id
      })
      if (res.status_code == 1) {
        this.optionsList.playletList = res.data.data
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.conten {
  .form {
    padding: 20px;
  }
}
</style>